package com.sky.mapper;

import com.sky.annotation.AutoInsertFill;
import com.sky.annotation.AutoUpdatetFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.vo.EmployeeOV;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * The interface Employee mapper.
 */
@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username the username
     * @return by username
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    /**
     * 员工分页查询
     *
     * @param epqDTO the epq dto
     * @return the list
     */
    List<Employee> selectList(EmployeePageQueryDTO epqDTO);


    /**
     * 根据账号查询是否有此账号
     *
     * @param username the username
     * @return the integer
     */
    @Select("select count(*) from employee where username = #{username}")
    Integer selectCountByUsername(@Param("username") String username);

    /**
     * 新增员工
     *
     * @param employee the employee
     */
    @AutoInsertFill
    void insert(Employee employee);


    /**
     * 更新状态
     *
     * @param employee the employee
     */
    @AutoUpdatetFill
    @Update("update employee set status =#{status},update_time = #{updateTime},update_user=#{updateUser} where id = #{id}")
    void updateStatus(Employee employee);


    /**
     * 根据id查询回显
     *
     * @param id the id
     * @return the employee ov
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user  from employee where id =#{id}")
    Employee selectById(@Param("id") Long id);


    /**
     * 非我根据账号查询是否有此账号
     *
     * @param username the username
     * @param id       the id
     * @return the boolean
     */
    @Select("select count(*) from employee where username = #{username} and id != #{id}")
    Integer selectCountByUsernameAndId(@Param("username") String username, @Param("id") Long id);


    /**
     * 更新账号信息
     *
     * @param employee the employee
     */
    void update(Employee employee);


    /**
     * 根据id进行跟新密码
     *
     * @param id       the id
     * @param password the password
     */
    @Update("update employee set password = #{password} where id = #{id} ")
    void updatePassword(@Param("id") Long id, @Param("password")String password);
}
